#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
ll num[10];
bool judge(ll n){
    for(ll i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    ll cnt=0;
    while(n){
        num[cnt++]=n%10;
        n/=10;
    }
    ll i,j;
    for(i=0,j=cnt-1;i<j;i++,j--){
        if(num[i]!=num[j])break;
    }
    if(i<j){
        return false;
    }
    return true;
}

int main()
{
    IOS;
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=11;i<=n;i++){
        if(judge(i))ans++;
    }
    cout<<ans<<endl;
    getchar();
    getchar();
    return 0;
}
